clear
set more off
capture log close
set matsize 10000

log using "tables.txt", replace


*Merge municipality data with kulturkampf data
do "prepare kulturkampf"

*Prepare interactions for acreg command

gen cath_prus = catholic_share*prussia
gen cath_oppress = catholic_share*intensity_court
gen cath_intens = catholic_share*ln_intensity

*********
*Table 1: AfD vote share on the municipal level 2017, West Germany
*********
eststo clear
quiet eststo Catholic: acreg afd_share catholic_share i.state [weight=voters] if east == 0, latitude(_CX) longitude(_CY) dist(50) spatial
quiet eststo Interact: acreg afd_share catholic_share prussia cath_prus i.state [weight=voters] if east == 0, latitude(_CX) longitude(_CY) dist(50) spatial
quiet eststo Full: acreg afd_share unemployment empl_marginal empl_regular population_1000 university foreign_share pop65_share female_share border_dist catholic_share prussia cath_prus i.state [weight=voters] if east == 0, latitude(_CX) longitude(_CY) dist(50) spatial
quiet eststo Intens: reg afd_share catholic_share intensity_court cath_oppress i.state [weight=voters] if east == 0, vce(cluster court_district)
quiet eststo Intens_cont: reg afd_share unemployment empl_marginal empl_regular population_1000 university foreign_share pop65_share female_share border_dist catholic_share intensity_court cath_oppress i.state [weight=voters] if east == 0, vce(cluster court_district)


estout, cells(b(star fmt(3)) se(par fmt(3))) starlevels(+ 0.10 * 0.05 ** 0.01 *** 0.001) ///
collab(none) stats(N r2, fmt(0 3)) legend numbers  drop (*.state) /// 
order (catholic_share prussia cath_prus intensity_court cath_oppress) 

*********
*Table 2: AfD vote share on the municipal level 2017, Rhineland-Palatinate
*********
eststo clear
quietly eststo Catholic: acreg afd_share catholic_share [weight=voters] if bundesland == "Rheinland-Pfalz", latitude(_CX) longitude(_CY) dist(40) spatial
quietly eststo Interact: acreg afd_share catholic_share prussia cath_prus [weight=voters] if bundesland == "Rheinland-Pfalz", latitude(_CX) longitude(_CY) dist(40) spatial
quietly eststo Full: acreg afd_share unemployment empl_marginal empl_regular population_1000 university foreign_share pop65_share female_share catholic_share prussia cath_prus [weight=voters] if bundesland == "Rheinland-Pfalz", latitude(_CX) longitude(_CY) dist(40) spatial
quietly eststo Intens: acreg afd_share catholic_share intensity_court cath_oppress [weight=voters] if bundesland == "Rheinland-Pfalz", latitude(_CX) longitude(_CY) dist(40) spatial
quietly eststo Intens_cont: acreg afd_share unemployment empl_marginal empl_regular population_1000 university foreign_share pop65_share female_share catholic_share intensity_court cath_oppress [weight=voters] if bundesland == "Rheinland-Pfalz", latitude(_CX) longitude(_CY) dist(40) spatial

estout, cells(b(star fmt(3)) se(par fmt(3))) starlevels(+ 0.10 * 0.05 ** 0.01 *** 0.001) ///
collab(none) stats(N r2, fmt(0 3)) legend numbers  drop () /// 
order (catholic_share prussia cath_prus intensity_court cath_oppress) 

*********
*Table 3: Association between Kulturkampf intensity and Catholic mobilization
*********
eststo clear
preserve
keep if east == 0
bysort court_district diocese_1990 : gen count = _N
sort court_district count

collapse (last) diocese diocese_1990 court_district (median) volksverein_1913 volksverein_1927 katholikentag_est cathpop1895 intensity_court, by (county1890)
collapse (last) diocese diocese_1990 (mean) volksverein_1913 volksverein_1927 katholikentag_est intensity_court (sum) cathpop1895, by (court_district)

*Standardize
center volksverein_1913 volksverein_1927 katholikentag_est intensity_court [], prefix(z_)  standardize 

*Regress
eststo std_VV_1913: reg z_volksverein_1913 z_intensity_court [weight=cathpop1895], vce(cluster diocese) 
eststo std_VV_1927: reg z_volksverein_1927 z_intensity_court [weight=cathpop1895], vce(cluster diocese) 
eststo std_VV_Katholikentage: reg z_katholikentag_est z_intensity_court [weight=cathpop1895], vce(cluster diocese_1990)  

estout, cells(b(star fmt(3)) se(par fmt(3))) starlevels(+ 0.10 * 0.05 ** 0.01 *** 0.001) ///
collab(none) stats(N r2, fmt(0 3)) legend numbers  drop ()
eststo clear
restore


*********
*Table 4: Analysis of mechanism
*********
eststo Interaction_1913: reg afd_share c.catholic_share##c.volksverein_1913 i.state [weight=voters] if east == 0, vce(cluster diocese)
eststo Interaction_1927: reg afd_share c.catholic_share##c.volksverein_1927 i.state [weight=voters] if east == 0, vce(cluster diocese)
eststo Katholikentage: reg afd_share c.catholic_share##c.katholikentag_est i.state [weight=voters] if east == 0, vce(cluster diocese_1990)
eststo Attendance: reg afd_share c.catholic_share##c.attendance i.state [weight=voters] if east == 0, vce(cluster diocese_1990)

estout, cells(b(star fmt(3)) se(par fmt(3))) starlevels(+ 0.10 * 0.05 ** 0.01 *** 0.001) ///
collab(none) stats(N r2, fmt(0 3)) legend numbers  drop (*.state)
eststo clear

*********
*Table 5: NSDAP results and Catholicism
*********
clear
use "dataset_Weimar.dta"

local weight1933 "r_wahlberechtigte_1933"
local weightNOV1932 "r_wahlberechtigte_NOV1932"
local weightJUL1932 "r_wahlberechtigte_JUL1932"
local weight1930 "r_wahlberechtigte_1930"
local rel2 "r_1925C_juden r_M1925C_juden r_1925C_others r_M1925C_others"
local demographics "r_1933C_frauen r_M1933C_frauen r_stadtkreis r_1925C_logtotpop r_M1925C_logtotpop"
local employment "r_1933C_arbfrau r_M1933C_arbfrau r_1933C_ang_arbeitslos r_M1933C_ang_arbeitslos r_1933C_arb_arbeitslos r_M1933C_arb_arbeitslos r_1933C_hausang_arbeitslos r_M1933C_hausang_arbeitslos"
local industry "r_1933C_ind r_M1933C_ind r_1933C_hand r_M1933C_hand r_1933C_oeffprivd r_M1933C_oeffprivd r_1933C_haus r_M1933C_haus"
local workforce "r_1933C_angest r_M1933C_angest r_1933C_beamt r_M1933C_beamt r_1933C_arb r_M1933C_arb r_1933C_hausang r_M1933C_hausang r_1933C_selbst r_M1933C_selbst"
local iFE "i.WKNR"
local FE "_WKNR*"
local geo "r_latitude r_longitude r_distance_berlin r_distance_nearestcity r_distance_border r_distance_seaport r_distance_river r_distance_resources"

eststo clear
quietly eststo Interact1932NOV: reg r_NSDAP_NOV1932_p c.r_1925C_kath##i.PRUSSIA   `rel2' `demographics' `employment' `industry' `workforce' `FE' `geo' [aw=`weightNOV1932'] if r_M1925C_kath==0 & r_MNSDAP_NOV1932_p==0, cluster(WKNR)
quietly eststo No_FE1930: reg r_NSDAP_1930_p  c.r_1925C_kath##i.PRUSSIA  `rel2' `demographics' `employment' `industry' `workforce' `geo' [aw=`weight1930'] if r_M1925C_kath==0 & r_MNSDAP_1930_p==0, cluster(WKNR)
quietly eststo No_FE1932JUL: reg r_NSDAP_JUL1932_p c.r_1925C_kath##i.PRUSSIA   `rel2' `demographics' `employment' `industry' `workforce' `geo' [aw=`weightJUL1932'] if r_M1925C_kath==0 & r_MNSDAP_JUL1932_p==0, cluster(WKNR)
quietly eststo No_FE1932NOV: reg r_NSDAP_NOV1932_p c.r_1925C_kath##i.PRUSSIA   `rel2' `demographics' `employment' `industry' `workforce' `geo' [aw=`weightNOV1932'] if r_M1925C_kath==0 & r_MNSDAP_NOV1932_p==0, cluster(WKNR)
quietly eststo No_FE1933: reg r_NSDAP_1933_p c.r_1925C_kath##i.PRUSSIA   `rel2' `demographics' `employment' `industry' `workforce' `geo' [aw=`weight1933'] if r_MNSDAP_1933_p==0 & r_M1925C_kath==0 , cluster(WKNR)

estout, cells(b(star fmt(3)) se(par fmt(3))) starlevels(+ 0.10 * 0.05 ** 0.01 *** 0.001) collab(none) stats(N r2, fmt(0 3)) legend numbers ///
drop (0.* _WKNR* r_M* _WK* r_d* r_1933* r_s* r_l* r_1925C_j* r_1925C_l* r_1925C_o*)

*********
*Table 6: Predicted affinity toward the AfD, GLES 2017
*********
clear

use "dataset_individual.dta", replace

keep if education > 0
keep if unemployed >= 0
keep if eligible == 1

eststo clear
quietly eststo prussia: logit thermometer_AfD_bin prussia gender age abitur unemployed std_income [pweight = vn_w_ipfwes] if catholic == 1 & eastwest == 1 & std_income >= 0 & thermometer_AfD > 0, vce(cluster Wahlkreis_Nr)
quietly eststo kulturkampf: logit thermometer_AfD_bin c.intensity_court gender age abitur unemployed std_income [pweight = vn_w_ipfwes] if catholic == 1 & eastwest == 1 & std_income >= 0 & thermometer_AfD > 0, vce(cluster Wahlkreis_Nr)
quietly eststo VV_1913: logit thermometer_AfD_bin c.volksverein_1913 gender age abitur unemployed std_income [pweight = vn_w_ipfwes] if catholic == 1 & eastwest == 1 & std_income >= 0 & thermometer_AfD > 0, vce(cluster Wahlkreis_Nr)
quietly eststo VV_1927: logit thermometer_AfD_bin c.volksverein_1927 gender age abitur unemployed std_income [pweight = vn_w_ipfwes] if catholic == 1 & eastwest == 1 & std_income >= 0 & thermometer_AfD > 0, vce(cluster Wahlkreis_Nr)
quietly eststo katholikentag: logit thermometer_AfD_bin c.katholikentag_est gender age abitur unemployed std_income [pweight = vn_w_ipfwes] if catholic == 1 & eastwest == 1 & std_income >= 0 & thermometer_AfD > 0, vce(cluster Wahlkreis_Nr)

estout, cells(b(star fmt(3)) se(par fmt(3))) starlevels(+ 0.10 * 0.05 ** 0.01 *** 0.001) /// ///
collab(none) stats(N r2_p, fmt(0 3)) legend numbers  ///
order (prussia intensity_court volksverein_1913 volksverein_1927 katholikentag_est) ///
drop() 

